package com.example.demo.mybatis.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.mybatis.entity.LffTestEntity;
import com.example.demo.mybatis.mapper.LffTestMapper;
import com.example.demo.mybatis.model.LffTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class TestDao {
    @Autowired
    private LffTestMapper lffTestMapper;

    public LffTestEntity selectByNo() {
        return lffTestMapper.selectByNo(new BigDecimal(1));
    }

    public List<LffTestEntity> selectByName() {
        return lffTestMapper.selectByName("a_first", "a_last");
    }

    public List<LffTestEntity> selectByBean() {
        LffTest bean = new LffTest();
        bean.setFirstName("a_first");
        bean.setLastName("a_last");
        return lffTestMapper.selectByBean(bean);
    }

    public List<LffTest> select21() {
        return lffTestMapper.select21(new BigDecimal(1));
    }

    public List<LffTestEntity> select22() {
        LffTestEntity whereEntity = new LffTestEntity();
        whereEntity.setFirstName("a_first");
        whereEntity.setLastName("a_last");
        return lffTestMapper.selectList(new QueryWrapper<>(whereEntity));
    }

    public List<LffTestEntity> select23() {
        return lffTestMapper.select23(new BigDecimal(1));
    }


    public int insert() {
        for (int i = 20; i < 30; i++) {
            LffTestEntity insertEntity = new LffTestEntity();
            insertEntity.setNo(new BigDecimal(i));
            insertEntity.setFirstName("a_first_" + i);
            insertEntity.setLastName("a_last_" + i);
            insertEntity.setScore(new BigDecimal(10 + i));
            System.out.println("insert==" + lffTestMapper.insert(insertEntity));
        }
        return 0;
    }


}
